package hnlg.com.cn.systemmanage.zhenqumanage.control;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import hnlg.com.cn.common.RespBean;
import hnlg.com.cn.model.ZhenquVo;
import hnlg.com.cn.systemmanage.zhenqumanage.service.IZhenquService;

@RestController
@RequestMapping("/zhenquControl")
public class ZhenquManageControl {
RespBean rb=null;
List<ZhenquVo> list=null;
@Resource IZhenquService ZhenquService;
//http://localhost:8044/test/zhenquControl/addzhenqu?name=郭家镇
@RequestMapping("/addzhenqu")
public RespBean addzhenqu(ZhenquVo vo){
	try{
		ZhenquService.addZhenqu(vo);
		rb=new RespBean("msg","添加成功");
	}catch(Exception e){
		e.printStackTrace();
		rb=new RespBean("msg","添加成功");
	}
	return rb;
}
//http://localhost:8044/test/zhenquControl/deletezhenqu?id=6
@RequestMapping("/deletezhenqu")
public RespBean deletezhenqu(@RequestParam("id") String id){
	try{
		System.out.println("id=="+id);
		ZhenquService.deleteZhenqu(id);
		rb=new RespBean("msg","删除成功");
	}catch(Exception e){
		e.printStackTrace();
		rb=new RespBean("msg","删除失败");
	}
	return rb;
}
//http://localhost:8044/test/zhenquControl/updatezhenqu?id=4&name=李家镇
@RequestMapping("/updatezhenqu")
public RespBean updatezhenqu(ZhenquVo vo){
	try{
		boolean flag=ZhenquService.updateZhenqu(vo);
		System.out.println("=="+flag);
		rb=new RespBean("msg","更新成功");
	}catch(Exception e){
		e.printStackTrace();
		rb=new RespBean("msg","更新失败");
	}
	return rb;
}

//http://localhost:8044/test/zhenquControl/queryzhenqu?
@RequestMapping("/queryzhenqu")
public List<ZhenquVo> queryzhenqu(
		@RequestParam(required=false,defaultValue="") String name){
	try{
		ZhenquVo vo=new ZhenquVo();
		vo.setName(name);
		list=ZhenquService.queryzhenqu(vo);
	}catch(Exception e){e.printStackTrace();}
	
	return list;
	
}
//http://localhost:8044/test/zhenquControl/deletezhenqubatch?ck=1,2,3,4
@RequestMapping("/deletezhenqubatch")
public RespBean deletezhenqubatch(@RequestParam("ck")String mycheckbox[]){
	try{
		for(String obj:mycheckbox){
			System.out.println("mycheckbox=="+obj);
		}
		boolean flag=ZhenquService.deletezhenqubatch(mycheckbox);
		System.out.println("flag=="+flag);
		rb=new RespBean("success","批量删除成功");
	}catch(Exception e){
		rb=new RespBean("success","批量删除失败");
		e.printStackTrace();
	}
	
	return rb;
	
}
}
